local SeasonRank
local SeasonMemberRank
local HasRelease

local panResult
local panMemberRank
local panSeasonRank
local panRank
local lstRank
local lstMemberRank

function ClubLS_ResultGUITryShowReward()
	if (panMemberRank:WasVisible() or panSeasonRank:WasVisible() or panRank:WasVisible()) then
		if (ProfileManager:Instance():GetGuildModel():HasGuildSeasonReward()) then
			MainMenuGUIComp:ShowGuildSeasonReward()
			ProfileManager:Instance():GetGuildModel():DelGuildSeasonReward()
		end
	end
end

local function ClubLS_ResultGUIShowResult()
	local seasonResult = ProfileManager:Instance():GetGuildModel():GetGuildSeasonResult()
	
	local seasonInfo = ProfileManager:Instance():GetGuildModel():GetGuildSeasonInfo()
	local labCurRound = NPObjectRef:DynamicCast("NPGUILabel", panResult:RecChildByName("Game_Day_number"))
	labCurRound:SetTextA(tostring(seasonInfo.currentRound%100))
	
	local maxRound    = ProfileManager:Instance():GetServerParam(34)
	local labAllRound = NPObjectRef:DynamicCast("NPGUILabel", panResult:RecChildByName("Game_Day_All_number"))
	labAllRound:SetTextA(tostring(maxRound))
	
	local panSelf = panResult:RecChildByName("Pan_MyClub")
	local panOppo = panResult:RecChildByName("Pan_OppoClub")

	local guildID = ProfileManager:Instance():GetPlayerData():GetGuildID()
	local guildInfo = ProfileManager:Instance():GetGuildModel():GetGuildInfo(guildID)
	if (guildInfo ~= nil) then
		local labSelfName = NPObjectRef:DynamicCast("NPGUILabel", panSelf:RecChildByName("club_name"))
		labSelfName:SetTextA(guildInfo.szName)
		local emblemInfo = ProfileManager:Instance():GetGuildModel():GetGuildEmblemHelper():GetGuildEmblemInfo(guildInfo.stCoreData.dwMedalID);
		if (emblemInfo ~= nil) then
			local picSelfIcon     = NPObjectRef:DynamicCast("NPGUIPicture", panSelf:RecChildByName("club_ico"))
			local picSelfIconBack = NPObjectRef:DynamicCast("NPGUIPictureCondition", panSelf:RecChildByName("PicCond_frame"))
			local picSelfIconFore = NPObjectRef:DynamicCast("NPGUIPictureCondition", panSelf:RecChildByName("PicCon_Decorate"))
			GUIUtils:SetGuildEmblemIcon(picSelfIcon, emblemInfo.szIcon, picSelfIconBack, picSelfIconFore, guildInfo.stCoreData.dwLevel)
		end
		
		local serverInfo = ProfileManager:Instance():GetGuildModel():GetGuildServerHelper():GetGuildServerInfo(guildInfo.stCoreData.stBelongSvr.dwGuildServerId)
		if (serverInfo ~= nil) then
			local labGuildServerName = NPObjectRef:DynamicCast("NPGUILabel", panResult:RecChildByName("area"))
			labGuildServerName:SetTextA(serverInfo.szName)
		end
		
		local labSelfLeadName = NPObjectRef:DynamicCast("NPGUILabel", panSelf:RecChildByName("Lab_Name"))
		GUIUtils:SetTrimLabelWithDot(labSelfLeadName, guildInfo.szChairmanNickname)
		local labSelfStar = NPObjectRef:DynamicCast("NPGUILabel", panSelf:RecChildByName("Lab_Star_number"))
		labSelfStar:SetTextA(tostring(seasonResult.iSelfStarCount))
		
		local labSelfMemNum = NPObjectRef:DynamicCast("NPGUILabel", panSelf:RecChildByName("Lab_member_number"))
		--local strSelfMemNum = ProfileManager:Instance():GetGuildModel():GetGuildMemberStr(guildInfo.stCoreData.dwLevel, seasonResult.iPKPlayerCount)
		labSelfMemNum:SetTextA(tostring(seasonResult.iPKPlayerCount))
		
		local picWin  = panSelf:RecChildByName("Pic_Win")
		local picLost = panSelf:RecChildByName("Pic_Lose")
		if (seasonResult.bIsWin == 0) then
			picWin:Hide()
			picLost:Show()
		else
			picWin:Show()
			picLost:Hide()
		end
	end
	
	local labOppoName = NPObjectRef:DynamicCast("NPGUILabel", panOppo:RecChildByName("club_name"))
	labOppoName:SetTextA(seasonResult.szEnmyName)
	local emblemInfo = ProfileManager:Instance():GetGuildModel():GetGuildEmblemHelper():GetGuildEmblemInfo(seasonResult.iEnmyIcon);
	if (emblemInfo ~= nil) then
		local picOppoIcon     = NPObjectRef:DynamicCast("NPGUIPicture", panOppo:RecChildByName("club_ico"))
		local picOppoIconBack = NPObjectRef:DynamicCast("NPGUIPictureCondition", panOppo:RecChildByName("PicCond_frame"))
		local picOppoIconFore = NPObjectRef:DynamicCast("NPGUIPictureCondition", panOppo:RecChildByName("PicCon_Decorate"))
		GUIUtils:SetGuildEmblemIcon(picOppoIcon, emblemInfo.szIcon, picOppoIconBack, picOppoIconFore, seasonResult.iEnmyLevel)
	end
	
	local labOppoLeadName = NPObjectRef:DynamicCast("NPGUILabel", panOppo:RecChildByName("Lab_Name"))
	GUIUtils:SetTrimLabelWithDot(labOppoLeadName, seasonResult.szEnmyChairmanName)
	local labOppoStar = NPObjectRef:DynamicCast("NPGUILabel", panOppo:RecChildByName("Lab_Star_number"))
	labOppoStar:SetTextA(tostring(seasonResult.iEnmyStarCount))
	
	local labOppoMemNum = NPObjectRef:DynamicCast("NPGUILabel", panOppo:RecChildByName("Lab_member_number"))
	--local strOppoMemNum = ProfileManager:Instance():GetGuildModel():GetGuildMemberStr(seasonResult.iEnmyLevel, seasonResult.iPKPlayerCount)
	labOppoMemNum:SetTextA(tostring(seasonResult.iPKPlayerCount))

	local panWinHint  = panResult:RecChildByName("Game_win_hint")
	local panLoseHint = panResult:RecChildByName("Game_lose_hint")
	
	local picWin  = panOppo:RecChildByName("Pic_Win")
	local picLose = panOppo:RecChildByName("Pic_Lose")
	if (seasonResult.bIsWin == 0) then
		picWin:Show()
		picLose:Hide()
		panWinHint:Hide()
		panLoseHint:Show()
	else
		picWin:Hide()
		picLose:Show()
		panWinHint:Show()
		panLoseHint:Hide()
	end

	local picAnim = panResult:RecChildByName("Animation")
	picAnim:Hide()
	if (seasonResult.bIsWin ~= 0) then
		picAnim:Show()
	end
	
	local labWinHonor = NPObjectRef:DynamicCast("NPGUILabel", panWinHint:RecChildByName("Lab_award_hint3"))
	local winHonor = ProfileManager:Instance():GetServerParam(40)
	labWinHonor:SetTextA(tostring(winHonor))
	local labLoseHonor = NPObjectRef:DynamicCast("NPGUILabel", panLoseHint:RecChildByName("Lab_award_hint3"))
	local loseHonor = ProfileManager:Instance():GetServerParam(41)
	labLoseHonor:SetTextA(tostring(loseHonor))
	
	panResult:Show()
end

local function ClubLS_ResultGUIShowMemberRank()
	local seasonResult = ProfileManager:Instance():GetGuildModel():GetGuildSeasonResult()
	
	local guildID = ProfileManager:Instance():GetPlayerData():GetGuildID()
	local guildInfo = ProfileManager:Instance():GetGuildModel():GetGuildInfo(guildID)
	if (guildInfo ~= nil) then
		local labGuildName = NPObjectRef:DynamicCast("NPGUILabel", panMemberRank:RecChildByName("Lab_headline"))
		labGuildName:SetTextA(guildInfo.szName)
		
		local emblemInfo = ProfileManager:Instance():GetGuildModel():GetGuildEmblemHelper():GetGuildEmblemInfo(guildInfo.stCoreData.dwMedalID);
		if (emblemInfo ~= nil) then
			local picGuildIcon     = NPObjectRef:DynamicCast("NPGUIPicture", panMemberRank:RecChildByName("club_ico"))
			local picGuildIconBack = NPObjectRef:DynamicCast("NPGUIPictureCondition", panMemberRank:RecChildByName("PicCond_frame"))
			local picGuildIconFore = NPObjectRef:DynamicCast("NPGUIPictureCondition", panMemberRank:RecChildByName("PicCon_Decorate"))
			GUIUtils:SetGuildEmblemIcon(picGuildIcon, emblemInfo.szIcon, picGuildIconBack, picGuildIconFore, guildInfo.stCoreData.dwLevel)
		end
		
		local serverInfo = ProfileManager:Instance():GetGuildModel():GetGuildServerHelper():GetGuildServerInfo(guildInfo.stCoreData.stBelongSvr.dwGuildServerId)
		if (serverInfo ~= nil) then
			local labGuildServerName = NPObjectRef:DynamicCast("NPGUILabel", panMemberRank:RecChildByName("Place"))
			labGuildServerName:SetTextA(serverInfo.szName)
		end
	end
	
	local maxRound    = ProfileManager:Instance():GetServerParam(34)
	local personLimit = ProfileManager:Instance():GetServerParam(36)
	local labPersonLimit = NPObjectRef:DynamicCast("NPGUILabel", panMemberRank:RecChildByName("People_Number"))
	labPersonLimit:SetTextA(tostring(personLimit))
	
	local seasonInfo = ProfileManager:Instance():GetGuildModel():GetGuildSeasonInfo()
	local labCurRound = NPObjectRef:DynamicCast("NPGUILabel", panMemberRank:RecChildByName("Lab_match_Number"))
	labCurRound:SetTextA(tostring(seasonInfo.currentRound%100).."/"..tostring(maxRound))
	
	local timeVec = GUIUtils:GetLocalTime(seasonInfo.pkTime)
	local year    = timeVec[1]
	local month   = timeVec[2]
	local day     = timeVec[3]
	local hour    = timeVec[4]
	local minute  = timeVec[5]
	local labRoundTime = NPObjectRef:DynamicCast("NPGUILabel", panMemberRank:RecChildByName("at_least"))
	labRoundTime:SetTextA(tostring(year).."."..tostring(month).."."..tostring(day).." "..string.format("%02d", hour)..":"..string.format("%02d", minute))
		
	panMemberRank:Show()
end

local function ClubLS_ResultGUIShowSeasonRank()
	local seasonInfo = ProfileManager:Instance():GetGuildModel():GetGuildSeasonInfo()
	local labCurRound = NPObjectRef:DynamicCast("NPGUILabel", panSeasonRank:RecChildByName("Game_Day_number"))
	labCurRound:SetTextA(tostring(seasonInfo.currentRound%100))
	
	local maxRound    = ProfileManager:Instance():GetServerParam(34)
	local labAllRound = NPObjectRef:DynamicCast("NPGUILabel", panSeasonRank:RecChildByName("Game_Day_All_number"))
	labAllRound:SetTextA(tostring(maxRound))
	
	local guildID = ProfileManager:Instance():GetPlayerData():GetGuildID()
	local guildInfo = ProfileManager:Instance():GetGuildModel():GetGuildInfo(guildID)
	if (guildInfo ~= nil) then
		local serverInfo = ProfileManager:Instance():GetGuildModel():GetGuildServerHelper():GetGuildServerInfo(guildInfo.stCoreData.stBelongSvr.dwGuildServerId)
		if (serverInfo ~= nil) then
			local labGuildServerName = NPObjectRef:DynamicCast("NPGUILabel", panSeasonRank:RecChildByName("area"))
			labGuildServerName:SetTextA(serverInfo.szName)
		end
	end
	
	panSeasonRank:Show()
end

local function ClubLS_ResultGUIShowGlobalRank()
	local seasonInfo = ProfileManager:Instance():GetGuildModel():GetGuildSeasonInfo()
	local labCurRound = NPObjectRef:DynamicCast("NPGUILabel", panRank:RecChildByName("Lab_match_Number"))
	labCurRound:SetTextA(tostring(seasonInfo.currentRound%100))
	
	local maxRound    = ProfileManager:Instance():GetServerParam(34)
	local labAllRound = NPObjectRef:DynamicCast("NPGUILabel", panRank:RecChildByName("all_bout_num"))
	labAllRound:SetTextA(tostring(maxRound))
	
	local guildID = ProfileManager:Instance():GetPlayerData():GetGuildID()
	local guildInfo = ProfileManager:Instance():GetGuildModel():GetGuildInfo(guildID)
	if (guildInfo ~= nil) then
		local serverInfo = ProfileManager:Instance():GetGuildModel():GetGuildServerHelper():GetGuildServerInfo(guildInfo.stCoreData.stBelongSvr.dwGuildServerId)
		if (serverInfo ~= nil) then
			local labGuildServerName = NPObjectRef:DynamicCast("NPGUILabel", panRank:RecChildByName("Place"))
			labGuildServerName:SetTextA(serverInfo.szName)
		end
		local regionInfo = ProfileManager:Instance():GetGuildModel():GetGuildRegionHelper():GetGuildRegionInfo(guildInfo.stCoreData.stBelongSvr.dwGuildMainlandId)
		if (regionInfo ~= nil) then
			local picGuildRegionIcon = NPObjectRef:DynamicCast("NPGUIPicture", panRank:RecChildByName("area_ico"))
			GUIUtils:SetGuildRegionIcon(picGuildRegionIcon, regionInfo.szIcon)
		end
	end
	
	panRank:Show()
end

local function ClubLS_ResultGUIShowRank()
	local seasonInfo = ProfileManager:Instance():GetGuildModel():GetGuildSeasonInfo()
	local curRound = seasonInfo.currentRound%100
	local maxRound = ProfileManager:Instance():GetServerParam(34)
	if (curRound == maxRound) then
		ClubLS_ResultGUIShowSeasonRank()
	else
		ClubLS_ResultGUIShowMemberRank()
	end
	
	ClubLS_ResultGUITryShowReward()
end

function ClubLS_ResultGUIOnErrorConfirm(index)
	MainMenuGUIComp:HideGuildSeasonResult()
end

function ClubLS_ResultGUIOnSeasonResultRes(errorCode)
	if (errorCode == 0) then
		if (not LocalSaveHelper:Instance():HasShowGuildSeasonResult()) then
			ClubLS_ResultGUIShowResult()
			
			LocalSaveHelper:Instance():SetShowGuildSeasonResult(true)
			LocalSaveHelper:Instance():SaveLocalInfo()
		else
			ClubLS_ResultGUIShowRank()
		end
	else
		ClubLS_ResultGUIShowRank()
		if 	   (errorCode == 1) then
			PopupGUI:Instance():ShowLocalizedMessage("TEXT_GUILD_BATTLE_MATCH_ERROR")
		elseif (errorCode == 2) then
			PopupGUI:Instance():ShowLocalizedMessage("TEXT_GUILD_BATTLE_MATCH_BYE")
		elseif (errorCode == 3) then
			PopupGUI:Instance():ShowLocalizedMessage("TEXT_GUILD_BATTLE_MATCH_STATUS_ERROR")
		elseif (errorCode == 4) then
			PopupGUI:Instance():ShowLocalizedMessage("TEXT_GUILD_BATTLE_MATCH_NOT_ENOUGH_PLAYER")
		elseif (errorCode == 5) then
			PopupGUI:Instance():ShowLocalizedMessage("TEXT_GUILD_BATTLE_MATCH_NOT_FOUND_PLAYER")
		elseif (errorCode == 6) then
			PopupGUI:Instance():ShowLocalizedMessage("TEXT_GUILD_BATTLE_MATCH_NOT_FOUND_ROUNDID")
		elseif (errorCode == 7) then
			PopupGUI:Instance():ShowLocalizedMessage("TEXT_GUILD_BATTLE_MATCH_NOT_FOUND_ENMY")
		end
	end
end

function ClubLS_ResultGUIRefreshMemberRank()
	SeasonMemberRank = ProfileManager:Instance():GetGuildModel():GetGuildSeasonMemberRank()
	lstMemberRank:DelItemAll()
	lstMemberRank:AddItem(0, #SeasonMemberRank)
	
	local labPersonNum = NPObjectRef:DynamicCast("NPGUILabel", panMemberRank:RecChildByName("People_Number_Now"))
	labPersonNum:SetTextA(tostring(#SeasonMemberRank))
end

function ClubLS_ResultGUIRefreshRank()
	SeasonRank = ProfileManager:Instance():GetGuildModel():GetGuildSeasonRank()
	lstRank:DelItemAll()
	lstRank:AddItem(0, #SeasonRank)
	
	local selfOrder = ProfileManager:Instance():GetGuildModel():GetGuildSeasonSelfOrder()
	local picNoRank = panMemberRank:RecChildByName("no_ranking")
	picNoRank:SetVisible(selfOrder > 50)
	local labNoRank = panRank:RecChildByName("lab_norank")
	labNoRank:SetVisible(#SeasonRank == 0)
	
	local panRankArray = {nil, nil, nil}
	panRankArray[1] = panSeasonRank:RecChildByName("No.One")
	panRankArray[2] = panSeasonRank:RecChildByName("No.Two")
	panRankArray[3] = panSeasonRank:RecChildByName("No.Three")
	for k,v in pairs(panRankArray) do
		local panInfo = v:RecChildByName("Pan_Info")
		local picWait = v:RecChildByName("Pic_Waiting")
		panInfo:Hide()
		picWait:Show()
	end
	
	local index = 1
	for k,v in pairs(SeasonRank) do
		local info = SeasonRank[index]
		local panInfo = panRankArray[index]:RecChildByName("Pan_Info")
		local picWait = panRankArray[index]:RecChildByName("Pic_Waiting")
		panInfo:Show()
		picWait:Hide()

		--level
		local labLevel = NPObjectRef:DynamicCast("NPGUILabel", panRankArray[index]:RecChildByName("Lab_LV"))
		labLevel:SetTextA(tostring(info.iGuildLevel))

		--icon
		local emblemInfo = ProfileManager:Instance():GetGuildModel():GetGuildEmblemHelper():GetGuildEmblemInfo(info.iGuildIcon);
		if (emblemInfo ~= nil) then
			local picGuildIcon     = NPObjectRef:DynamicCast("NPGUIPicture", panRankArray[index]:RecChildByName("Pic_Icon"))
			local picGuildIconBack = NPObjectRef:DynamicCast("NPGUIPictureCondition", panRankArray[index]:RecChildByName("PicCond_frame"))
			local picGuildIconFore = NPObjectRef:DynamicCast("NPGUIPictureCondition", panRankArray[index]:RecChildByName("PicCon_Decorate"))
			GUIUtils:SetGuildEmblemIcon(picGuildIcon, emblemInfo.szIcon, picGuildIconBack, picGuildIconFore, info.iGuildLevel)
		end
		
		--lead
		local labLead = NPObjectRef:DynamicCast("NPGUILabel", panRankArray[index]:RecChildByName("president_name"))
		GUIUtils:SetTrimLabelWithDot(labLead, info.szLeaderPlayerName)

		--name
		local labName = NPObjectRef:DynamicCast("NPGUILabel", panRankArray[index]:RecChildByName("club_name"))
		labName:SetTextA(info.szGuildName)
		
		--star
		local labStar = NPObjectRef:DynamicCast("NPGUILabel", panRankArray[index]:RecChildByName("Lab_Star"))
		labStar:SetTextA(tostring(info.iGuildStarValue))
		
		index = index+1
		if (index > 3) then
			break
		end
	end

	local selfOrder = ProfileManager:Instance():GetGuildModel():GetGuildSeasonSelfOrder()
	local starCount = ProfileManager:Instance():GetGuildModel():GetGuildSeasonStarCount()
	local panSelf = panSeasonRank:RecChildByName("MY")
	local panInfo = panSelf:RecChildByName("Pan_Info")
	local picWait = panSelf:RecChildByName("Pic_Waiting")
	panInfo:SetVisible(selfOrder >  0)
	picWait:SetVisible(selfOrder == 0)
	
	local guildID = ProfileManager:Instance():GetPlayerData():GetGuildID()
	local guildInfo = ProfileManager:Instance():GetGuildModel():GetGuildInfo(guildID)
	if (guildInfo ~= nil) then
		--level
		local labLevel = NPObjectRef:DynamicCast("NPGUILabel", panSelf:RecChildByName("Lab_LV"))
		labLevel:SetTextA(tostring(guildInfo.stCoreData.dwLevel))

		--icon
		local emblemInfo = ProfileManager:Instance():GetGuildModel():GetGuildEmblemHelper():GetGuildEmblemInfo(guildInfo.stCoreData.dwMedalID);
		if (emblemInfo ~= nil) then
			local picGuildIcon     = NPObjectRef:DynamicCast("NPGUIPicture", panSelf:RecChildByName("Pic_Icon"))
			local picGuildIconBack = NPObjectRef:DynamicCast("NPGUIPictureCondition", panSelf:RecChildByName("PicCond_frame"))
			local picGuildIconFore = NPObjectRef:DynamicCast("NPGUIPictureCondition", panSelf:RecChildByName("PicCon_Decorate"))
			GUIUtils:SetGuildEmblemIcon(picGuildIcon, emblemInfo.szIcon, picGuildIconBack, picGuildIconFore, guildInfo.stCoreData.dwLevel)
		end
		
		--lead
		local labLead = NPObjectRef:DynamicCast("NPGUILabel", panSelf:RecChildByName("president_name"))
		GUIUtils:SetTrimLabelWithDot(labLead, guildInfo.szChairmanNickname)

		--name
		local labName = NPObjectRef:DynamicCast("NPGUILabel", panSelf:RecChildByName("club_name"))
		labName:SetTextA(guildInfo.szName)
		
		--star
		local labStar = NPObjectRef:DynamicCast("NPGUILabel", panSelf:RecChildByName("Lab_Star"))
		labStar:SetTextA(tostring(starCount))
	end
	
	local labSeasonRank = NPObjectRef:DynamicCast("NPGUILabel", panSelf:RecChildByName("No"))
	labSeasonRank:SetTextA(tostring(selfOrder))
	local picRewardNone = panSelf:RecChildByName("no_ranking")
	local labRewardHave = panSelf:RecChildByName("Have_to_receive")
	picRewardNone:Hide()
	labRewardHave:Hide()
end

function ClubLS_ResultGUIOnDelChild(args)
	HasRelease = true
end

function ClubLS_ResultGUIOnLoadFinish(args)
	HasRelease = false
	
	panResult 		= args.sender:RecChildByName("Pan_MatchResult")
	panMemberRank 	= args.sender:RecChildByName("Pan_MemberRank")
	panSeasonRank 	= args.sender:RecChildByName("Pan_RankShow")
	panRank 		= args.sender:RecChildByName("Pan_ClubRank")
	lstRank 		= NPObjectRef:DynamicCast("NPGUIListBoxCol", args.sender:RecChildByName("ClubRank"))
	lstMemberRank 	= NPObjectRef:DynamicCast("NPGUIListBoxCol", args.sender:RecChildByName("Member"))
end

function ClubLS_ResultGUIOnMemberItemShow(args)
	local index = args.item:GetIndex()+1

	local info = SeasonMemberRank[index]
	local isPlayer = (ProfileManager:Instance():GetPlayerData():GetAccountID() == info.szOpenId)
	
	args.item:SetUserText(info.szOpenId)
	
	--background
	local picBG = NPObjectRef:DynamicCast("NPGUIPictureCondition", args.item:RecChildByName("PicCon_BG"))
	if (isPlayer) then
		picBG:SetIndex(0)
	else
		picBG:SetIndex(1)
	end
	
	--rank
	local labRankMyself = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("LB_Rank"))
	local labRankOthers = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("LB_RankingTop"))
	labRankMyself:SetVisible(isPlayer)
	labRankOthers:SetVisible(not isPlayer)
	labRankMyself:SetTextA(tostring(index))
	labRankOthers:SetTextA(tostring(index))
	
	--icon
	local picHead = NPObjectRef:DynamicCast("NPGUIRemotePicture", args.item:RecChildByName("RemPic_Avatar"))
	picHead:DeleteTexture()
	picHead:Redraw()
	UserImageMgr:Instance():SetContentLua("ClubLS_ResultGUIUserImageCallback", info.szOpenId, GuildModel:GetLogoUrl(info.szPotraitURL))
	
	--gender
	local picGender = NPObjectRef:DynamicCast("NPGUIPictureCondition", args.item:RecChildByName("PictureCond_man_ico"))
	picGender:SetIndex(info.bGender-1)
	
	--friend
	--local piccFriend = NPObjectRef:DynamicCast("NPGUIPictureCondition", args.item:RecChildByName("Piccon_Friend"))
	--GUIUtils:DisplayFriend(piccFriend, rankData.openid)
	
	--lead
	--local piccLead = NPObjectRef:DynamicCast("NPGUIPictureCondition", args.item:RecChildByName("president"))
	--local guildID = ProfileManager:Instance():GetPlayerData():GetGuildID()
	--local memberPos = ProfileManager:Instance():GetGuildModel():GetGuildMemberPos(guildID, rankData.openid)
	--piccLead:SetIndex(memberPos)
	
	local labNameMyself = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("lab_Name"))
	local labNameOthers = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("Lab_Name2"))
	GUIUtils:SetTrimLabelWithDot(labNameMyself, info.szNickname)
	GUIUtils:SetTrimLabelWithDot(labNameOthers, info.szNickname)
	labNameMyself:SetVisible(isPlayer)
	labNameOthers:SetVisible(not isPlayer)
	
	local labStarMyself = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("Lab_Star"))
	local labStarOthers = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("Lab_Star2"))
	labStarMyself:SetTextA(tostring(info.iGetStar))
	labStarOthers:SetTextA(tostring(info.iGetStar))
	labStarMyself:SetVisible(isPlayer)
	labStarOthers:SetVisible(not isPlayer)
	
	local labTextMyself = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("LB_Content"))
	local labTextOthers = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("LB_Content2"))
	labTextMyself:SetVisible(isPlayer)
	labTextOthers:SetVisible(not isPlayer)
end

function ClubLS_ResultGUIUserImageCallback(openid, errorCode)
	if (HasRelease) then
		return
	end
	
	local children = lstMemberRank:GetChildren();
	for k,v in pairs(children) do
		if (v:GetUserText() == openid) then
			local picHead = NPObjectRef:DynamicCast("NPGUIRemotePicture", v:RecChildByName("RemPic_Avatar"))
			UserImageMgr:Instance():SetPictureContent(picHead, openid)
			break
		end
	end
end

function ClubLS_ResultGUIOnClubItemShow(args)
	local index = args.item:GetIndex()+1

	local info = SeasonRank[index]
	local isPlayer = (ProfileManager:Instance():GetPlayerData():GetGuildID() == info.iGuildId)
	
	--background
	local picBG = NPObjectRef:DynamicCast("NPGUIPictureCondition", args.item:RecChildByName("PicCon_BG"))
	if (isPlayer) then
		picBG:SetIndex(0)
	else
		picBG:SetIndex(1)
	end
	
	--rank
	local labRankMyself = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("Lab_Number"))
	local labRankOthers = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("Lab_Number2"))
	labRankMyself:SetVisible(isPlayer)
	labRankOthers:SetVisible(not isPlayer)
	labRankMyself:SetTextA(tostring(index))
	labRankOthers:SetTextA(tostring(index))
	
	--level
	local labLevel = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("Lab_LV"))
	labLevel:SetTextA(tostring(info.iGuildLevel))
	
	--icon
	local emblemInfo = ProfileManager:Instance():GetGuildModel():GetGuildEmblemHelper():GetGuildEmblemInfo(info.iGuildIcon);
	if (emblemInfo ~= nil) then
		local picGuildIcon     = NPObjectRef:DynamicCast("NPGUIPicture", args.item:RecChildByName("PicCon_Photo"))
		local picGuildIconBack = NPObjectRef:DynamicCast("NPGUIPictureCondition", args.item:RecChildByName("PicCond_frame"))
		local picGuildIconFore = NPObjectRef:DynamicCast("NPGUIPictureCondition", args.item:RecChildByName("PicCon_Decorate"))
		GUIUtils:SetGuildEmblemIcon(picGuildIcon, emblemInfo.szIcon, picGuildIconBack, picGuildIconFore, info.iGuildLevel)
	end
	
	--lead
	local labLeadMyself = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("Lab_Name"))
	local labLeadOthers = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("Lab_Name2"))
	GUIUtils:SetTrimLabelWithDot(labLeadMyself, info.szLeaderPlayerName)
	GUIUtils:SetTrimLabelWithDot(labLeadOthers, info.szLeaderPlayerName)
	labLeadMyself:SetVisible(isPlayer)
	labLeadOthers:SetVisible(not isPlayer)

	--name
	local labNameMyself = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("Lab_Clubname"))
	local labNameOthers = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("Lab_Clubname2"))
	labNameMyself:SetTextA(info.szGuildName)
	labNameOthers:SetTextA(info.szGuildName)
	labNameMyself:SetVisible(isPlayer)
	labNameOthers:SetVisible(not isPlayer)
	
	--star
	local labStarMyself = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("Lab_Star01"))
	local labStarOthers = NPObjectRef:DynamicCast("NPGUILabel", args.item:RecChildByName("Lab_Star02"))
	labStarMyself:SetTextA(tostring(info.iGuildStarValue))
	labStarOthers:SetTextA(tostring(info.iGuildStarValue))
	labStarMyself:SetVisible(isPlayer)
	labStarOthers:SetVisible(not isPlayer)
end

function ClubLS_ResultGUIOnShow(args)
	panResult:Hide()
	panMemberRank:Hide()
	panSeasonRank:Hide()
	panRank:Hide()
	
	NetworkOpManager:Instance():ReqGuildSeasonResult()
	NetworkOpManager:Instance():ReqGuildSeasonRank()
	NetworkOpManager:Instance():ReqGuildSeasonMemberRank()
	
	ClubLS_ResultGUIRefreshMemberRank()
	ClubLS_ResultGUIRefreshRank()
end

function ClubLS_ResultGUIOnClickCloseResult(args)
	panResult:Hide()
	ClubLS_ResultGUIShowRank()
end

function ClubLS_ResultGUIOnClickCloseMemberRank(args)
	local seasonInfo = ProfileManager:Instance():GetGuildModel():GetGuildSeasonInfo()
	local curRound = seasonInfo.currentRound%100
	local maxRound = ProfileManager:Instance():GetServerParam(34)
	if (curRound == maxRound) then
		panMemberRank:Hide()
		ClubLS_ResultGUIShowSeasonRank()
	else
		MainMenuGUIComp:HideGuildSeasonResult()
	end
end

function ClubLS_ResultGUIOnClickRule(args)
	MainMenuGUIComp:ShowGuildSeasonRule()
end

function ClubLS_ResultGUIOnClickRank(args)
	panMemberRank:Hide()
	panSeasonRank:Hide()
	ClubLS_ResultGUIShowGlobalRank()
end

function ClubLS_ResultGUIOnClickCloseRank(args)
	panRank:Hide()
	ClubLS_ResultGUIShowRank()
end

function ClubLS_ResultGUIOnClickCloseSeasonRank(args)
	MainMenuGUIComp:HideGuildSeasonResult()
end

function ClubLS_ResultGUIOnClickMemberRank(args)
	panSeasonRank:Hide()
	ClubLS_ResultGUIShowMemberRank()
end

function ClubLS_ResultGUIOnClickDetail(args)
	local panRankArray = {nil, nil, nil}
	panRankArray[1] = panSeasonRank:RecChildByName("No.One")
	panRankArray[2] = panSeasonRank:RecChildByName("No.Two")
	panRankArray[3] = panSeasonRank:RecChildByName("No.Three")
	for i=1,#panRankArray do
		if (args.sender:WasAncestor(panRankArray[i])) then
			MainMenuGUIComp:ShowGuildInfo(SeasonRank[i].iGuildId)
			break
		end
	end
end

function ClubLS_ResultGUIOnUpdate(args)
	local seasonInfo = ProfileManager:Instance():GetGuildModel():GetGuildSeasonInfo()
	if (GUIUtils:CheckTimeExpire(seasonInfo.finalTime)) then
		MainMenuGUIComp:HideGuildSeasonResult()
	end
end